#include "Key_Support.h"

/*
*@brief This function will set portd to input mode,
and ready to recieve number. It can't enable interrupt
becasue F877A do not support RD interrupt.
Please note that PORTD[0:1] will be cleared!!!
*@param None
*retval None
*/
void key_init(void){
	portd &= ~(0b00000011);
	trisd |= 0b00000011;
	nop();
}

/*
*@brief This function will scan key for one time
*@param None
*retval KEY0_ID, KEY1_ID or NOT_DETECT
*/
unsigned char key_scan(void){
	delay_10us(2);
	if(test_bit(portd,KEY0) == 0){
		return KEY0_ID;
	}else if(test_bit(portd,KEY1) == 0){
		return KEY1_ID;
	}else{
		return NOT_DETECT;
	}
}